

import createStatementData from './createStatementData.js'

export default function htmlStatement(invoice, plays) {
    return renderHtml(createStatementData(invoice, plays));
}
function renderHtml(data) {

    let result = `<h1>Statement for ${data.customer}</h1>\n`;
    result += `<table>\n`;
    result += `<tr><th>play</th><th>seats</th><th>cost</th></tr>`;
    for (let perf of data.performances) {
        result += `<tr><td>${perf.play.name}</td><td>${perf.audience}</td>`;
        result += `<td>${usd(perf.amount)}</td></tr>\n`;
    }

    result += `</table>\n`;
    debugger
    result += `<p>Amount owed is <em>${usd(data.totalAmount)}</em></p>\n`;
    result += `<p>You earned <em>${usd(data.totalVolumeCredits)}</em>Credits</p>\n`;
    return result;

}
function usd(aNumber) {
    return new Intl.NumberFormat("en-US", {
      style: "currency",
      currency: "USD",
      mininumFractionDigits: 2
    }).format(aNumber / 100);
  }